<%-- 
    Document   : comminsert2
    Created on : 2014/2/24, 下午 05:21:20
    Author     : Gjun
--%>

<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
        request.setCharacterEncoding("UTF-8");           
        pic.pic pp = new pic.pic(request);
        
    %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
         if((pp.getParameter("name")!="")&&(pp.getParameter("price")!="")&&(pp.getParameter("num")!="")&&(pp.getParameter("say")!=""))
        {            
                int x= new db.SQLC().insert(pp.getParameter("name"),pp.getParameter("price"),pp.getParameter("num") ,pp.getParameter("say"));                      
                System.out.println("異動"+x+"筆資料");                 
                 String dao=new db.SQLC().getLast();
                 //查詢是否錯誤       
                       String msg = pp.checkUpload();
                         if (msg.length() > 0) {
                                 out.println(msg);
                        } else {
                            //設定上傳路徑
                                  pp.setUploadDir(this.getServletContext().getRealPath("/")+"productPic\\");
                                  
                                   // out.println("上傳到此路徑:" + this.getServletContext().getRealPath(".") + "<br/>");
                                    //取得文字檔
                                    //out.println("文字欄位:" + pp.getParameter("textfield") + "<br/>");
                                     //開始上傳
                                   
                                  if (pp.isExtUpload("file"))
                                             msg = pp.doUpload(pp.getUploadParameter("file"),dao);                                   
                                    if (msg.length() > 0)
                                            out.println(msg);
                                    else
                                            out.println("上傳成功" + "<br/>"); 
                               
                                 }
        }else{                    
                        out.print("<font size='3' color='red'>資料不可空白</font>"); 
                        out.print("<meta http-equiv='refresh' content='2;url=http://10.10.3.14:8084/web4/comminsert.jsp?產品名稱="+pp.getParameter("name")+"&產品價格="+pp.getParameter("price")+"&庫存量="+pp.getParameter("num")+"&產品介紹="+pp.getParameter("say")+"' />");
                }
                         %>
       
        <form action="comminsert.jsp">
            <input type="submit" value="繼續新增">
        </form>
        <form action="listdb.jsp">
                <input type="submit" value="產品清單" >
            </form>
    </body>
</html>
